package com.cloud.drore.eboss.supplier.controller;

import com.cloud.drore.eboos.common.base.PagePo;
import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.dealer.OrderInitVo;
import com.cloud.drore.eboos.common.entity.supplier.Ticket;
import com.cloud.drore.eboos.common.entity.supplier.po.TicketQueryPo;
import com.cloud.drore.eboos.common.entity.supplier.vo.TicketAllVo;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.login.user.Anon;
import com.cloud.drore.eboss.supplier.entity.po.ProductInfoResponsePo;
import com.cloud.drore.eboss.supplier.entity.po.SupplierTicketUpdPo;
import com.cloud.drore.eboss.supplier.entity.po.TickPo;
import com.cloud.drore.eboss.supplier.service.ITicketOrderFeign;
import com.cloud.drore.eboss.supplier.service.impl.TicketServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.ResultSet;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/8 11:07 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@RestController
@RequestMapping("/ticket")
@Api(value = "/门票接口", description = "门票接口-郑永涛")
public class TicketController {

    @Resource
    TicketServiceImpl ticketService;
    @Autowired
    ITicketOrderFeign ticketOrderFeign;


    /**
     * @ClassName: TicketController
     * @param resultSet
     * @Return: java.sql.ResultSet
     * @Decription:
     * @CreateDate: Created in 2018/1/8 11:14
     * @Author: <a href="575842778@qq.com">郑永涛</a>
     * @Modify:
     */
    public ResultSet get(ResultSet resultSet){
        return null;
    }

    @ApiOperation(value = "根据条件分页查询门票信息运营商接口")
    @PostMapping(value = "/findTicketByParam")
    public ResultMessage<TicketAllVo> findTicketByParam(@RequestBody PagePo<TicketQueryPo> pagePo) throws BusinessException{
        return ResultMessage.success(ticketService.findTicketByParam(pagePo));
    }

    @Anon
    @ApiOperation(value = "根据条件查询门票信息分销商接口")
    @PostMapping(value = "/findTicketByParamDealer")
    public ResultMessage<TicketAllVo> findTicketByParamDealer(@RequestBody PagePo<TicketQueryPo> pagePo) throws BusinessException{
        return ResultMessage.success(new PageInfo(ticketService.findTicketByParamDealer(pagePo)));
    }

    @ApiOperation(value = "根据条件查询门票信息供应商接口")
    @PostMapping(value = "/findTicketByParamSupplier")
    public ResultMessage<TicketAllVo> findTicketByParamSupplier(@RequestBody PagePo<TicketQueryPo> pagePo) throws BusinessException{
        return ResultMessage.success(new PageInfo(ticketService.findTicketByParamSupplier(pagePo)));
    }

    @ApiOperation(value = "保存门票信息")
    @PostMapping(value = "/saveTicket")
    public ResultMessage<Ticket> saveTicket(@RequestBody TickPo tickPo) throws BusinessException {
        return ticketService.insertTicket(tickPo.getTicket(),tickPo.getTicketPrice());
    }

    @ApiOperation(value = "更新门票信息 ")
    @PutMapping(value = "/updateTicket")
    public ResultMessage<Ticket> updateTicket(@RequestBody TickPo tickPo) throws BusinessException {
        return ticketService.updateTicket(tickPo.getTicket(),tickPo.getTicketPrice(),tickPo.getTicketStocks());
    }

    @ApiOperation(value = "更新门票信息 ")
    @PutMapping(value = "/updateTicketSupplier")
    public ResultMessage<Ticket> updateTicketSupplier(@RequestBody SupplierTicketUpdPo supplierTicketUpdPo) throws BusinessException {
        return ticketService.updateTicketSupplier(supplierTicketUpdPo);
    }

    @Anon
    @ApiOperation(value = "查询门票信息详情")
    @GetMapping(value = "/selectTicketById/{id}")
    public ResultMessage<TicketAllVo> selectTicketById(@PathVariable("id") Long id) throws BusinessException {
        return ticketService.selectTicketById(id);
    }

    @ApiOperation(value = "查询门票信息详情")
    @GetMapping(value = "/selectTicketByIdSupplier/{id}")
    public ResultMessage<TicketAllVo> selectTicketByIdSupplier(@PathVariable("id") Long id) throws BusinessException {
        return ticketService.selectTicketByIdSupplier(id);
    }

    @ApiOperation(value = "上下架、审核产品，更改产品状态")
    @GetMapping(value = "/updateStatus/{id}/{status}/{commonProductId}")
    public ResultMessage<Ticket> updateStatus(@PathVariable("id") Long id, @PathVariable("status") String status,@PathVariable("commonProductId") Long commonProductId) throws BusinessException {
        return ticketService.updateStatus(id,status,commonProductId);
    }

    @ApiOperation(value = "审核驳回")
    @GetMapping(value = "/reject/{id}/{status}/{rejectReason}")
    public ResultMessage<Ticket> rejectProduct(@PathVariable("id") Long id, @PathVariable("status") String status,@PathVariable("rejectReason") String rejectReason) throws BusinessException {
        return ticketService.rejectProduct(id,status,rejectReason);
    }

    @Anon
    @ApiOperation(value = "根据编号查门票")
    @RequestMapping(value = "/selectTicketByNum/{productNum}", method = RequestMethod.GET)
    public ResultMessage<TicketAllVo> selectTicketByNum(@PathVariable(value = "productNum") String productNum){
        return ResultMessage.success(ticketService.selectTicketByProNum(productNum));
    }

    @ApiOperation(value = "查看驳回信息")
    @GetMapping(value = "/selectRejectInfoByProId/{commonId}")
    public ResultMessage selectRejectInfoByProId(@PathVariable("commonId") Long commonId) throws BusinessException {
        return ticketService.selectRejectInfoByProId(commonId);
    }

    @ApiOperation(value = "供应商门票订单页面加载初始化数据")
    @GetMapping(value = "/init")
    public ResultMessage<OrderInitVo> supplierInit() {
        return ticketService.init();
    }

    @ApiOperation(value = "新增门票输入产品代码同步畅游通产品接口-杨亮")
    @GetMapping(value = "/synchronizeProduct")
    public ResultMessage<ProductInfoResponsePo> synchronizeProduct(String productCode) throws BusinessException {
        return ticketService.synchronizeProduct(productCode);
    }
    @ApiOperation(value = "新增门票产品代码验重接口-杨亮")
    @GetMapping(value = "/isCodeUnique")
    public ResultMessage isCodeUnique(String productCode) throws BusinessException {
        return ticketService.isCodeUnique(productCode);
    }
}